/****************************************************************************
**
** Skills.cpp
**
** Copyright (C) August 2014 Hotride
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
*****************************************************************************
*/
//---------------------------------------------------------------------------
#include "stdafx.h"
//---------------------------------------------------------------------------
TSkill::TSkill()
: m_BaseValue(0.0f), m_Value(0.0f), m_Cap(0.0f), m_Status(0)
{
}
//---------------------------------------------------------------------------
bool TSkillSort::SkillCmp(const char *str1, int len1, const char *str2, int len2)
{
	int len = len1;
	if (len > len2) len = len2;
	
	IFOR(i, 0, len)
	{
		if (str1[i] < str2[i]) return true;
		else if (str1[i] > str2[i]) return false;
	}

	return false;
}
//---------------------------------------------------------------------------
void TSkillSort::Init()
{
	memset(m_Skills, 0xFF, sizeof(m_Skills));

	BYTE SkillBuf[60];
	memset(SkillBuf, 0xFF, sizeof(SkillBuf));

	int Count = UO->m_SkillsCount;
	PSKILLS_DATA Skills = UO->m_Skills;

	int Parsed = 0;

	IFOR(i, 0, Count)
	{
		//trace_printf("Skill[%d] = %s\n", i, Skills[i].SkillName);
		if (Parsed)
		{
			IFOR(j, 0, Parsed)
			{
				if (SkillCmp(Skills[SkillBuf[j]].m_Name.c_str(), Skills[SkillBuf[j]].m_Name.length(), Skills[i].m_Name.c_str(), Skills[i].m_Name.length()))
				{
					BYTE buf = SkillBuf[j];
					SkillBuf[j] = (BYTE)i;

					j++;

					for(; j < Parsed; j++)
					{
						BYTE ptr = SkillBuf[j];
						SkillBuf[j] = buf;
						buf = ptr;
					}

					SkillBuf[Parsed] = buf;

					Parsed++;
					break;
				}
			}
		}
		else
		{
			SkillBuf[0] = (BYTE)i;
			Parsed = 1;
		}
	}

	for (int i = 0, j = Parsed - 1; i < Parsed; i++, j--)
	{
		m_Skills[i] = SkillBuf[j];
	}
}
//---------------------------------------------------------------------------